// pages/more/article.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData(options)
        this.setData({
            station_id: getApp().station_id ? getApp().station_id : ''
        })
        this.loadData()
    },
    loadData() {
        let {
            list = [],
                page = 0,
                nextFlag = true,
                loading = false
        } = this.data
        if (loading || !nextFlag) return
        wx.showLoading({
            title: '加载中...',
        })
        this.setData({
            loading: true
        })
        app.http.get('city/msg/get-article-by-article', {
            data: {
                page,
                member_id: getApp().station_id ? getApp().station_id : ''
            }
        }).then(res => {
            page++
            loading = false
            nextFlag = res.data.nextFlag
            list.push(...res.data.articleData)
            for (var i = 0; i < list.length; i++) {
                list[i].img = list[i].msg_content.find(o => {
                    return o.images
                })
            }
            this.setData({
                page,
                nextFlag,
                loading,
                list
            })
            wx.hideLoading()
        }).catch(err => {

        })
    },
    onPullDownRefresh: function() {
        this.setData({
            page: 0,
            loading: false,
            list: [],
            nextFlag: true
        })
        this.loadData()
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        this.loadData()
    }
})